package com.ren.mianshi.http2.retrofit.interceptor;

import android.text.TextUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * retrofit拦截器，请求与相应的业务处理
 * Created by ren on 2017/9/12.
 */

public class HandlerInterceptor implements Interceptor {

	public Response intercept(Chain chain) throws IOException {
		Request request = handlerRequest(chain.request());
		return handlerResponse(chain, request);
	}

	private Request handlerRequest(Request request) {
		String sessionId =  "";
		String version = "1.0";
		Request newRequest = request.newBuilder()
				.addHeader("Sources", "Android")
				.addHeader("Versions", version).build();
		if (!TextUtils.isEmpty(sessionId)) {
			newRequest = newRequest.newBuilder()
					.addHeader("Session-Id", sessionId).build();
		}
		return newRequest;

	}


	private Response handlerResponse(Chain chain, Request request) throws IOException {
		Response resp = chain.proceed(request);
		return resp;
	}
}
